package com.xja.webchat.controller;

import com.xja.webchat.entity.Chatuser;
import com.xja.webchat.service.ChatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class WebController {
    @Autowired
    private ChatUserService chatUserService;

    @GetMapping("selectById")
    public Map<String,Object> selectById(Integer id, Model model){
        Map<String,Object> resuMap = new HashMap<>();
        try{
            System.out.println("sadoisajdohwohadoi");
            Chatuser chatuser = chatUserService.selectUserById(id);
            model.addAttribute("chatuser",chatuser);

            resuMap.put("status","true");
            resuMap.put("chatuser",chatuser);
            return resuMap;
        }catch (Exception ex){
            ex.printStackTrace();
        }
        resuMap.put("status","false");
        return resuMap;
    }

    @PostMapping("reg_useradd")
    public Map<String,Object> reg_useradd(@RequestBody Chatuser chatuser){
        Map<String,Object> resuMap = new HashMap<>();
        try{
            chatUserService.addChatuser(chatuser);
            resuMap.put("status","true");
            return resuMap;
        }catch (Exception ex){
            ex.printStackTrace();
        }
        resuMap.put("status","false");
        return resuMap;
    }

}
